﻿using Microsoft.EntityFrameworkCore;
using WebApplication3.Model;

namespace WebApplication3.Data
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

        public DbSet<Category> Categories { get; set; }
        public DbSet<Question> Questions { get; set; }
        public DbSet<TestResult> TestResults { get; set; }
        public DbSet<TestScore> TestScores { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Question>()
               .HasKey(q => new { q.Id, q.CategoryId });
            modelBuilder.Entity<TestScore>().ToTable("TestScores");
            modelBuilder.Entity<TestScore>()
                .Property(t => t.Id)
                .ValueGeneratedOnAdd(); // 确保 Id 字段被配置为自动生成
        }
        public DbSet<Login> Login { get; set; }
        public DbSet<User> User { get; set; }
    }
}
